﻿namespace WillSortSimulation;

public class WillPlanGenerator
{
    private void GeneratePlanRandom()
    {
        
    }

    private int[] GetSchoolIDs(School[] schools)
    {
        var result = new int[schools.Length];
        for (int i = 0; i < schools.Length; i++)
        {
            result[i] = schools[i].SchoolID;
        }

        return result;
    }
    
    private int[] GetSchoolIDsRevers(School[] schools)
    {
        var result = new int[schools.Length];
        for (int i = 0; i < schools.Length; i++)
        {
            result[i] = schools[schools.Length - i - 1].SchoolID;
        }

        return result;
    }

    private void RandomArray(int[] arr)
    {
        for (int i = 0; i < arr.Length-1; i++)
        {
            var r = RandomManager.Get().Next(i, arr.Length);
            // swap arr[i] , arr[r]
            (arr[i], arr[r]) = (arr[r], arr[i]);
        }
    }
    
    public WillPlan[] GeneratePlansRandom(int totalStudentNum, int planSchoolNum, School[] schools)
    {
        var plans = new WillPlan[totalStudentNum];

        var ids = GetSchoolIDs(schools);
        
        for (int i = 0; i < totalStudentNum; i++)
        {
            plans[i] = new WillPlan(i, planSchoolNum);
            RandomArray(ids);
            plans[i].FillPlan(ids);
            plans[i].planType = PlanType.Random;
        }

        return plans;
    }
    
    public WillPlan[] GeneratePlansSorted(int totalStudentNum, int planSchoolNum, School[] schools)
    {
        var plans = new WillPlan[totalStudentNum];

        var ids = GetSchoolIDsRevers(schools);
        
        for (int i = 0; i < totalStudentNum; i++)
        {
            plans[i] = new WillPlan(i, planSchoolNum);
            plans[i].FillPlan(ids);
            plans[i].planType = PlanType.Sorted;
        }

        return plans;
    }
}